<template>
	<div class="view">
		<!-- <template>
			<Top :title="'留言列表'"></Top>
		</template> -->
		<div class="header">
			<div class="h_exit" @click="toIndex">
				<i class="i-exit i-20 i-mr-10"></i>
				<div class="h_str">返回上一页</div>
			</div>
			<div class="h_con">
				<div class="h_li">维权咨询</div>
			</div>
		</div>

		<div class="main">
			<div class="main_con">
				<div class="m_title">维权咨询</div>
				<div class="line">
					<div class="search">
						<el-input placeholder="请输入关键词" suffix-icon="el-icon-search" v-model="keywords"
							@change="search" size="medium" style="width: 200px;">
						</el-input>
						<el-button type="primary" size="medium" @click="search">搜索</el-button>
					</div>
				</div>

				<div class="table">
					<el-table style="width: 100%;" :data="dataList" :height="table_height">
						<el-table-column type="selection" min-width="5%" align="center">
						</el-table-column>
						<el-table-column type="index" :index="1" label="行号" min-width="10%" align="center">
						</el-table-column>
                        <el-table-column prop="type" label="角色" min-width="15%" align="center">
							<template slot-scope="scope">
								<span>{{ scope.row.type==1?"企业":"求职者" }}</span>
							</template>
						</el-table-column>
                        <el-table-column prop="name" label="姓名" min-width="20%" align="center">
							<template slot-scope="scope">
								<span>{{ scope.row.isNiming==1?"匿名":scope.row.name }}</span>
							</template>
						</el-table-column>
                        <el-table-column prop="tel" label="联系方式" min-width="20%" align="center">
						</el-table-column>
						<el-table-column prop="sort" label="类别" min-width="20%" align="center">
						</el-table-column>
						<el-table-column prop="cnt" label="内容" min-width="30%" align="center">
							<template slot-scope="scope">
								<span>{{ scope.row.cnt || "-" }}</span>
							</template>
						</el-table-column>
                        <el-table-column prop="timeCreate" label="留言日期" min-width="20%" align="center">
						</el-table-column>
						<el-table-column prop="isContact" label="是否联系" min-width="15%" align="center">
							<template slot-scope="scope">
								<el-switch v-model="scope.row.isContact" active-color="#13ce66" inactive-color="#A5ADBA"
									:active-value="1" :inactive-value="0" @change="isOkHandler(scope.row)">
								</el-switch>
							</template>
						</el-table-column>
						<el-table-column prop="teacher" label="操作" min-width="30%" align="center">
							<template slot-scope="scope">
								<!-- <el-button size="mini" plain @click="edit(scope.row)">编辑</el-button> -->
								<el-button size="mini" plain @click="remove(scope.row)">移除</el-button>
							</template>
						</el-table-column>
					</el-table>
				</div>
				<div class="item_bottom">
					<div class="item_num">共{{ total }}条信息</div>
					<div class="item_page">
						<el-pagination background layout="prev, pager, next" :total="total"
							@current-change="handleCurrentChange">
						</el-pagination>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import Top from "../../../components/top.vue"
export default {
	components: {
		Top,
	},
	data() {
		const validatePass1 = (rule, value, callback) => {
			if (!this.checkPassword(value)) {
				callback(new Error("6-16位字符，必须为数字+字母组合(可以支持特殊符号)"));
				return;
			}
			if (this.form2.confirmPwd !== '') {
				this.$refs.form2.validateField('confirmPwd');
			}
			callback();
		};

		const validatePass2 = (rule, value, callback) => {
			if (value === '') {
				callback(new Error('请再次输入密码'));
			} else if (value != this.form2.newPwd) {
				callback(new Error('确认密码与新密码不一致，请重新输入'));
			} else {
				callback();
			}
		}
		return {
			keywords: "",
			table_height: document.documentElement.clientHeight - 360,
			diaHeight: document.documentElement.clientHeight - 142,
			dataList: [],
			total: 10,
			dialogVisible: false,

			form: {
				adminname: "",
				pwd: "",
				pwd2: "",
				id: "",
			},
			rules: {
				pwd: [
					{ required: true, validator: validatePass1, trigger: ['blur,change'] }
				],
				pwd2: [
					{ required: true, validator: validatePass2, trigger: ['blur,change'] }
				]
			},

			li_num: 1,
			left: 0,
			current: 1,
			limit: 10,
			isEdit:false,
		}

	},
	methods: {


		// 修改用户
		edit(item){
			this.$store.commit("setUrlParma",{id:item.id})
			this.$router.push("/recruit/update")
		},

		// 是否有效
		isOkHandler(item) {
			this.$http({
				url: this.$api.weiquanUpdate,
				method: 'post',
				data: {
					id: item.id,
					isContact: item.isContact
				}
			}).then(res => {
				if (res.data.code == 20000) {
					this.$message.success(res.data.message)
				} else {
                    item.isContact = item.isContact==0? 1:0
					this.$message.error(res.data.message)
				}
			})
		},

		// 搜索
		search() {
			this.current = 1
			this.dataInit()
		},
		toIndex() {
			this.$router.push('/server')
		},
		

		dataInit() {
			this.$http({
				'method': 'post',
				'url': this.$api.weiquanList,
				data: {
					current: this.current,
					limit: this.limit,
					keywords: this.keywords
				}
			}).then(res => {
				if (res.data.code == 20000) {
					this.dataList = res.data.data.list
					this.total = res.data.data.total
					console.log(this.dataList)
				}
			})
		},


		// 分页
		handleCurrentChange(num) {
			this.current = num;
			this.dataInit();
		},

		//图片上传成功后
		handleUploadSuccess(data) {
			this.cropperModel = false;
			this.cropperName = '';
			this.form1.picdir = data.url
		},

		// 删除
		remove(item) {
				this.$confirm('是否删除此信息?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url:this.$api.weiquanRemove+item.id
					}).then(res =>{
						if(res.data.code==20000){
							this.$message.success(res.data.message);
							this.dataInit();
						}else{
							this.$message(res.data.message)
						}
					})
				}).catch(() => {
					
				});
			},
	},
	created() {
		this.dataInit()
	}

}
</script>

<style scoped>
@import url(../../../assets/css/class.css);
</style>
